﻿using Learn.API.Models;
using Learn.Service;
using Microsoft.AspNetCore.Mvc;

namespace Learn.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LabuladongController : ControllerBase
    {
        #region test
        [HttpGet]
        public void Test()
        {
            int j = 0;
            int jj = 0;
            int jjj = 0;
            for (int i = 0; i < 10; i++)
            {
                j = j++;
                jj = jj + 1;
                jjj++;
            }
            Console.WriteLine(j);//0
            Console.WriteLine(jj);//10
            Console.WriteLine(jjj);//10

            int count = 0;
            int size = 100000;
            for (int i = 0; i < size; i++)
                count++;
            Console.WriteLine(count);
        }


        //Console.WriteLine("--------");
        //int j2 = 0;
        //for (int i = 0;i < 10;i++)
        //{
        //    j2= ++j2;
        //}
        //Console.WriteLine(j2);//10

        [HttpGet]
        public void TestAny()
        {
            List<SelectItem> items = [ 
                new (code:"1",name:"1",isSelected:false),
                new (code:"2",name:"2",isSelected:false),
                new (code:"3",name:"3",isSelected:true)
            ];
            if (items.Any(i => i.IsSelected == true))
            {

            }

            Foo foo = null;
            var n = 2 + foo?.N ?? 1;


        }

        #endregion

        #region GetFibRes
        /// <summary>
        /// 斐波那契数列
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        [HttpGet]
        public int GetFibRes(int i) => LabuladongService.GetFib(i);
        //{

        //    //var all = Seasons.All;
        //    //var allCode= all.GetHashCode();

        //    //Console.WriteLine(all);
        //    //return LabuladongService;
        //    return LabuladongService.GetFib(i);
        //}

        #endregion

        #region BinarySearch
        /// <summary>
        /// 二分查找
        /// </summary>
        /// <param name="ints">集合</param>
        /// <param name="target">目标</param>
        /// <returns>返回结果，有结果直接返回索引位置，否则返回-1</returns>
        [HttpPost]
        public int BinarySearch(int[] ints, int target) => LabuladongService.BinarySearch(ints, target);

        #endregion

        #region LeftBound
        /// <summary>
        /// LeftBound
        /// </summary>
        /// <param name="nums">集合</param>
        /// <param name="target"></param>
        /// <returns></returns>
        [HttpPost]
        public int LeftBound1(int[] nums, int target) => LabuladongService.LeftBound1(nums, target);
        /// <summary>
        /// LeftBound
        /// </summary>
        /// <param name="nums">集合</param>
        /// <param name="target"></param>
        /// <returns></returns>
        [HttpPost]
        public int LeftBound2(int[] nums, int target) => LabuladongService.LeftBound2(nums, target);

        #endregion

        #region RightBound
        /// <summary>
        /// RightBound1
        /// </summary>
        /// <param name="nums"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        [HttpPost]
        public int RightBound1(int[] nums, int target) => LabuladongService.RightBound1(nums, target);
        /// <summary>
        /// RightBound2
        /// </summary>
        /// <param name="nums"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        [HttpPost]
        public int RightBound2(int[] nums, int target) => LabuladongService.RightBound1(nums, target);


        #endregion

        #region MinWindow
        /// <summary>
        /// 最小子串
        /// </summary>
        /// <param name="s"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpGet]
        public string MinWindow(string s, string t) => LabuladongService.MinWindow(s, t);


        #endregion
        [HttpGet]
        public void PlusPlus()
        {
            int i = 1, j = 1;
            
            if (i >= j && i <= j && i != j)
            {

            }
            object oo = 1;
            object oo2 = 1;
            int ii =(int)oo;
            int jj =(int)oo2;

        }

    }

    [Flags]
    public enum Seasons
    {
        None = 0,
        Summer = 1,
        Autumn = 2,
        Winter = 4,
        Spring = 8,
        All = Summer | Autumn | Winter | Spring
    }

    public class Color(byte r, byte g, byte b)
    {
        public static readonly Color Black = new(0, 0, 0);
        public static readonly Color White = new(255, 255, 255);
        public static readonly Color Red = new(255, 0, 0);
        public static readonly Color Green = new(0, 255, 0);
        public static readonly Color Blue = new(0, 0, 255);
        public byte R = r;
        public byte G = g;
        public byte B = b;
    }

    class Foo
    {
        public int N { get; } = 1;
    }

}
